//
//  HomeRecommendTableCell.m
//  DanaKreditLoan
//
//  Created by ZhengChengFeng on 2024/10/19.
//

#import "HomeListTableCell.h"

@implementation HomeListTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        self.backV = [[UIView alloc] init];
        self.backV.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.backV];
        [self.backV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.top.equalTo(self.contentView.mas_top);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
        
        
        self.shadeView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, kScreenWidth - 60, 111)];
        [self.shadeView.layer addSublayer:[self colorFrameWidth:kScreenWidth - 60 withHeight:111 withColorAry:@[
            (__bridge id)[UIColor colorWithHexString:@"#EBFEEF"].CGColor,
            (__bridge id)[UIColor colorWithHexString:@"#FFFFFF"].CGColor,
        ]]];
        self.shadeView.backgroundColor = [UIColor clearColor];
        [self.backV addSubview:self.shadeView];
        [self.shadeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backV.mas_left).offset(15);
            make.right.equalTo(self.backV.mas_right).offset(-15);
            make.top.equalTo(self.backV.mas_top).offset(15);
            make.bottom.equalTo(self.backV.mas_bottom);
        }];
        self.shadeView.layer.cornerRadius = 14;
        self.shadeView.layer.masksToBounds = YES;
        
        
        self.iconV = [[UIImageView alloc] init];
        [self.shadeView addSubview:self.iconV];
        [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.shadeView.mas_left).offset(15);
            make.width.with.height.equalTo(@21);
            make.top.equalTo(self.shadeView.mas_top).offset(20);
        }];
        
        self.lab1 = [UILabel createLabel:[UIFont fontWithName:kFutura size:15] color:kBlackColor];
        [self.shadeView addSubview:self.lab1];
        [self.lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconV.mas_right).offset(4);
            make.right.equalTo(self.shadeView.mas_right).offset(-110);
            make.height.equalTo(@20);
            make.centerY.equalTo(self.iconV.mas_centerY);
        }];
        
        self.lab2 = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:kButtonDefaultColor];
        [self.shadeView addSubview:self.lab2];
        [self.lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.shadeView.mas_right).offset(-15);
            make.width.equalTo(@75);
            make.height.equalTo(@30);
            make.centerY.equalTo(self.iconV.mas_centerY);
        }];
        self.lab2.textAlignment = 1;
        self.lab2.layer.cornerRadius = 15;
        self.lab2.layer.masksToBounds = YES;
        self.lab2.layer.borderColor = kButtonDefaultColor.CGColor;
        self.lab2.layer.borderWidth = 1;
        
        

        self.lab3 = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:kButtonDefaultColor];
        [self.shadeView addSubview:self.lab3];
        [self.lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconV.mas_left);
            make.width.equalTo(@100);
            make.height.equalTo(@20);
            make.top.equalTo(self.iconV.mas_bottom).offset(16);
        }];
        
        self.lab3Desc = [UILabel createLabel:[UIFont fontWithName:kFutura size:12] color:[UIColor colorWithHexString:@"#6C6C6C"]];
        [self.shadeView addSubview:self.lab3Desc];
        [self.lab3Desc mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lab3.mas_left);
            make.width.equalTo(@100);
            make.height.equalTo(@20);
            make.top.equalTo(self.lab3.mas_bottom);
        }];
        
        self.lab4 = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:kBlackColor];
        [self.shadeView addSubview:self.lab4];
        [self.lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.shadeView.mas_left).offset((kScreenWidth - 60)/2 - 30);
            make.width.equalTo(@(100));
            make.height.equalTo(@20);
            make.top.equalTo(self.lab3.mas_top);
        }];
        
        self.lab4Desc = [UILabel createLabel:[UIFont fontWithName:kFutura size:12] color:[UIColor colorWithHexString:@"#6C6C6C"]];
        [self.shadeView addSubview:self.lab4Desc];
        [self.lab4Desc mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lab4.mas_left);
            make.width.equalTo(self.lab4.mas_width);
            make.height.equalTo(@20);
            make.top.equalTo(self.lab4.mas_bottom);
        }];
        
        self.lab5 = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:kBlackColor];
        [self.shadeView addSubview:self.lab5];
        [self.lab5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lab2.mas_left);
            make.right.equalTo(self.shadeView.mas_right);
            make.height.equalTo(@20);
            make.top.equalTo(self.lab3.mas_top);
        }];
        
        self.lab5Desc = [UILabel createLabel:[UIFont fontWithName:kFutura size:12] color:[UIColor colorWithHexString:@"#6C6C6C"]];
        [self.shadeView addSubview:self.lab5Desc];
        [self.lab5Desc mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lab5.mas_left);
            make.width.equalTo(self.lab5.mas_width);
            make.height.equalTo(@20);
            make.top.equalTo(self.lab5.mas_bottom);
        }];
        
    
        
    }
    return self;
}

- (void)setModel:(ProductListModel *)model{
    _model = model;
    
    
    if (PMStringIsEmpty(model.widespread)) {
        self.iconV.image = [UIImage imageNamed:@"icon_Logo2"];
    } else {
        [self.iconV sd_setImageWithURL:[NSURL URLWithString:esString(model.widespread)]];
    }
    self.lab1.text = esString(model.caulfeild);
    self.lab2.text = ASLocalizedString(@"Apply");
    self.lab3.text = esString(model.kai);
    self.lab3Desc.text = ASLocalizedString(@"home5Str");
    self.lab4.text = esString(model.objective);
    self.lab4Desc.text = ASLocalizedString(@"home6Str");
    self.lab5.text =esString(model.killing);
    self.lab5Desc.text = ASLocalizedString(@"home7Str");
    
    self.lab3.adjustsFontSizeToFitWidth = YES;
    self.lab4.adjustsFontSizeToFitWidth = YES;
    self.lab5.adjustsFontSizeToFitWidth = YES;
    
}

- (CALayer *)colorFrameWidth:(CGFloat)width withHeight:(CGFloat)height withColorAry:(NSArray *)colorAry{
    CAGradientLayer *gradientLayer =  [CAGradientLayer layer];
    gradientLayer.frame = CGRectMake(0, 0, width, height);
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1,0);
    gradientLayer.locations = @[@(0.0),@(1.0)];
    gradientLayer.colors = colorAry;
    return gradientLayer;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
